package com.chen.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * com.example.demo.controller
 * 作者      : 陈晓
 * 描述      :
 * 创建日期  : 2018/4/24
 * 修改日期  :
 */

@Controller
@RequestMapping("/index")
public class IndexController {

  private final String cookieName = "username";
  private final String visitPage = "visit/visitList";
  private final String customerPage = "customer/customerList";

  @RequestMapping("/login")
  public String hello() {
    return "login";
  }

  @RequestMapping("/main")
  public String mian(HttpServletRequest request) {
    return "main";
  }

  @RequestMapping("/visit")
  public String visit() {
    return visitPage;
  }

  @RequestMapping("/customer")
  public String customer() {
    return customerPage;
  }

  /**
   * 根据cookie里面
   * @param request
   * @return
   */
  private String getCookieValue(HttpServletRequest request) {
    String cookieValue = "index";
    Cookie[] cookies = request.getCookies();
    for (int i = 0; i < cookies.length; i++) {
      String cookieName = cookies[i].getName();
      if (cookies[i].getName().equals(cookieName)) {
        String value = cookies[i].getValue();
        if (value != null) {
          cookieValue = "main";
        }
      }
    }
    return cookieValue;
  }

}
